<?php if(!defined('ARCH_ROOT_PATH')) exit;
/**
 *	Architect Framework
 *
 *	Architect Framework is a light weight object oriented web applications framework written for PHP 5.1.4 and later that provide the tools to develop and deploy a website or application fast and with as little code as possible.
 *
 *	@author Robin Grass, <hello@coffinboy.se>
 *	@link http://architect.kodlabbet.net
 *	@license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License (v. 3)
 */

/**
 *	Architect
 *
 *	This singleton class has no "real" purpose but to hold all Architect classes used by the framework, it provides fast and dynamic initalization of classes and saves the instance holder to the Architect::$instances property. This class has a lot of "magic methods", such as __clone, __get and __set. You can read more about it at - http://us2.php.net/manual/en/language.oop5.magic.php
 *
 *	@package Core
 *	@version 1.0
 *	@author Robin Grass, <hello@coffinboy.se>
 */
class Architect {

	/**
	 *	@staticvar resource $__instance
	 */
	private static $__instance;
	
	/**
	 *	@var array $instances Instance holders.
	 */
	protected $instances = array();
	
	/**
	 *	__construct
	 */
	protected function __construct() {}

	/**
	 *	__clone
	 */
	final private function __clone() {}
	
	/**
	 *	getInstance
	 *
	 *	This is method is the most important part of a singleton pattern, it returns the current instance of this class (if any). If the class has not been instanced this method creates a new instance and returns it.
	 *
	 *	@return self::$__instance
	 */
	static public function getInstance() {
		if(!self::$__instance)
			self::$__instance = new self();
	return self::$__instance;
	}

	/**
	 *	__get
	 *
	 *	@param string $name
	 *
	 *	@return resource
	 */
	public function __get($instance) {
		return $this->instances[$instance];
	}

	/**
	 *	__set
	 *
	 *	@param string $instance
	 *	@param mixed $object
	 */
	public function __set($instance, $object) {
		$this->instances[$instance] = $object;
	}
	
	/**
	 *	initialize
	 *
	 *	This method dynamically creates a new instance of a class, including parameters and method to call first.
	 *
	 *	@param string $class
	 *	@param string $instance
	 *	@param array $parameters
	 *	@param string $method
	 */
	public function initialize($class, $instance, $parameters = array(), $method = 'newInstance') {
		$this->$instance = call_user_func_array(array(new ReflectionClass($class), $method), $parameters);
	}

}
?>